
import os

buildmode = ARGUMENTS.get('mode', 'release')

if not (buildmode in ['debug', 'release']):
    print "Error: 'mode' option expected 'debug' or 'release', found: " + buildmode
    Exit(1)

support_graphics = (
    'WGL',
    'GLX',
#    'AGL',
#    'EGL',
    'None'
)

graphics = ARGUMENTS.get('graphics', None)

if not(graphics):
   if os.name == 'posix':
       graphics = 'GLX'
   elif os.name == 'mac':
       graphics = 'AGL'
   elif os.name == 'nt':
       graphics = 'WGL'
   else:
       graphics = 'EGL'

if graphics not in support_graphics:
   print "Error: 'graphics' option expected " + ' or '.join(support_graphics) + ", found: " + graphics
   Exit(1)

targetroot=os.path.join('#' + buildmode, 'lib')

env = Environment(
    CPPPATH = '#alkes/include',
    LIBPATH = targetroot)

debugflags=['-g', '-Wall', '-D_DEBUG']
releaseflags=['-O2', '-Wall', '-DNDEBUG']

Export('env', 'targetroot', 'buildmode', 'debugflags', 'releaseflags', 'graphics')

buildroot=os.path.join('builds', buildmode)
#filelist = map(lambda x: str(x).replace('src', buildroot), Glob('src/*/*.cpp') + Glob('src/sys/*/*.cpp'))

localenv = env.Clone()

if buildmode == 'debug':
    localenv.Append(CCFLAGS=debugflags)
else:
    localenv.Append(CCFLAGS=releaseflags)


projects = [
    'alkes',
    'tree',
    'tree3d',
    'gfxfilter',
    'testdriver',
    'codec',
    'opengl'
]

if graphics == 'None':
    projects.remove('opengl')


#localenv.Alias('all', target)
#localenv.Alias('alkes', target)

import os

for project in projects:
    SConscript(os.path.join(project, 'SConscript'), exports=['project'])

